/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package myprogramui.comp;

import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.control.Tooltip;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.RectangleBuilder;
import javafx.stage.Stage;
import myprogramui.MyProgramUI;

/**
 *
 * @author Administrator
 */
public class LeftButton extends Group{
    private Stage primaryStage;
    private Rectangle center;
    private Line line;
    private boolean flag1=false;
    private boolean flag2=true;
    private boolean flag3=true;
    //三个蒙版
    private Rectangle mengbanYC;
    private Rectangle mengbanSZ;
    private Rectangle mengban2D;
    //各种tooltip
    Tooltip szTip=new Tooltip("文件导入\n初始参数设定\n文件导出");
    Tooltip tdTip=new Tooltip("对注浆孔在2维平面内进行绘制");
    Tooltip ycTip=new Tooltip("对钻孔数据进行汇总分析");
    public LeftButton(Line line,Rectangle center,Stage primaryStage,final MyProgramUI myProgramUI){
        this.primaryStage=primaryStage;
        this.center=center;
        this.line=line;
        final Rectangle iv_but_back=RectangleBuilder.create()
                .strokeWidth(0)
                .width(100)
                .height(100)
                .fill(Color.WHITESMOKE)
                .x(16)
                .y(95)
                .build();
        this.getChildren().add(iv_but_back);
        iv_but_back.widthProperty().bind(line.endXProperty().subtract(20));
        iv_but_back.heightProperty().bind(center.heightProperty().divide(3).subtract(12));
        final Rectangle iv_but1_back=RectangleBuilder.create()
                .strokeWidth(0)
                .width(100)
                .height(100)
                .fill(Color.WHITESMOKE)
                .x(16)
                .y(95)
                .build();
        this.getChildren().add(iv_but1_back);
        iv_but1_back.yProperty().bind(center.heightProperty().divide(3).add(85));
        iv_but1_back.widthProperty().bind(line.endXProperty().subtract(20));
        iv_but1_back.heightProperty().bind(center.heightProperty().divide(3).subtract(4));
        final Rectangle iv_but2_back=RectangleBuilder.create()
                .strokeWidth(0)
                .width(100)
                .height(100)
                .fill(Color.WHITESMOKE)
                .x(16)
                .y(95)
                .build();
        this.getChildren().add(iv_but2_back);
        iv_but2_back.yProperty().bind(center.heightProperty().divide(3).multiply(2).add(85));
        iv_but2_back.widthProperty().bind(line.endXProperty().subtract(20));
        iv_but2_back.heightProperty().bind(center.heightProperty().divide(3).add(6));
        //左侧三个按钮
        ImageView iv_but1=new ImageView("Image_no_pair/cirani/shezhi.png");
        ImageView iv_but2=new ImageView("Image_no_pair/cirani/2d.png");
        ImageView iv_but3=new ImageView("Image_no_pair/cirani/tongji.png");
        iv_but1.setTranslateX(55);
        iv_but2.setTranslateX(55);
        iv_but3.setTranslateX(55);
        iv_but1.translateYProperty().bind(center.heightProperty().divide(3).subtract(70));
        iv_but2.translateYProperty().bind(center.heightProperty().divide(3).multiply(2).subtract(70));
        iv_but3.translateYProperty().bind(center.heightProperty().divide(3).multiply(3).subtract(70));
        this.getChildren().add(iv_but1);
        this.getChildren().add(iv_but2);
        this.getChildren().add(iv_but3);
        
        mengbanSZ=RectangleBuilder.create()
                .strokeWidth(0)
                .fill(Color.WHITESMOKE)
                .width(120)
                .height(150)
                .opacity(0.0f)
                .build();
        mengbanSZ.setTranslateX(55);
        mengbanSZ.translateYProperty().bind(center.heightProperty().divide(3).subtract(70));
        this.getChildren().add(mengbanSZ);
        mengbanSZ.setOnMouseEntered(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                mengbanSZ.setOpacity(0f);
            }
        });
        mengbanSZ.setOnMouseExited(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                if(flag1){
                    mengbanSZ.setOpacity(0.78f);
                }                    
            }
        });
        
        //蒙版2d
        mengban2D=RectangleBuilder.create()
                .strokeWidth(0)
                .fill(Color.WHITESMOKE)
                .width(120)
                .height(150)
                .opacity(0.78f)
                .build();
        mengban2D.setTranslateX(55);
        mengban2D.translateYProperty().bind(center.heightProperty().divide(3).multiply(2).subtract(70));
        this.getChildren().add(mengban2D);
        mengban2D.setOnMouseEntered(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                mengban2D.setOpacity(0f);
            }
        });
        mengban2D.setOnMouseExited(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                if(flag2){
                    mengban2D.setOpacity(0.78f);
                }
                
            }
        });
        
        //蒙版yuce
        mengbanYC=RectangleBuilder.create()
                .strokeWidth(0)
                .fill(Color.WHITESMOKE)
                .width(120)
                .height(150)
                .opacity(0.78f)
                .build();
        mengbanYC.setTranslateX(55);
        mengbanYC.translateYProperty().bind(center.heightProperty().divide(3).multiply(3).subtract(70));
        this.getChildren().add(mengbanYC);
        mengbanYC.setOnMouseEntered(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                mengbanYC.setOpacity(0f);
            }
        });
        mengbanYC.setOnMouseExited(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                if(flag3){
                    mengbanYC.setOpacity(0.78f);
                }               
            }
        });
        
        final Rectangle arrow=RectangleBuilder.create()
                .opacity(0)
                .width(15)
                .height(55)
                .fill(Color.rgb(225, 233, 220, .99))
                .strokeWidth(0)
                .build();
        this.getChildren().add(arrow);
        arrow.heightProperty().bind(center.heightProperty().divide(3).subtract(12));
        arrow.xProperty().bind(line.startXProperty().subtract(7));
        arrow.setTranslateY(95);
        final Rectangle arrow1=RectangleBuilder.create()
                .width(15)
                .height(55)
                .fill(Color.rgb(225, 233, 220, .99))
                .strokeWidth(0)
                .build();
        this.getChildren().add(arrow1);
        arrow1.heightProperty().bind(center.heightProperty().divide(3).subtract(4));
        arrow1.xProperty().bind(line.startXProperty().subtract(7));
        arrow1.yProperty().bind(center.heightProperty().divide(3).add(85));
        final Rectangle arrow2=RectangleBuilder.create()
                .width(15)
                .height(55)
                .fill(Color.rgb(225, 233, 220, .99))
                .strokeWidth(0)
                .build();
        this.getChildren().add(arrow2);
        arrow2.heightProperty().bind(center.heightProperty().divide(3).add(6));
        arrow2.xProperty().bind(line.startXProperty().subtract(7));
        arrow2.yProperty().bind(center.heightProperty().multiply(2).divide(3).add(85));
        //相应事件处理
        iv_but_back.setOpacity(0);
        arrow.setOpacity(1);
        arrow1.setOpacity(0);
        arrow2.setOpacity(0);
        mengban2D.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                mengbanYC.setOpacity(0.87);
                mengbanSZ.setOpacity(0.87f);
                mengban2D.setOpacity(0f);
                flag2=false;
                flag1=true;
                flag3=true;
                arrow.setOpacity(0);
                arrow1.setOpacity(1);
                arrow2.setOpacity(0);
                //背景
                iv_but_back.setOpacity(1);
                iv_but1_back.setOpacity(0);
                iv_but2_back.setOpacity(1);
                myProgramUI.setPage(!flag1, !flag2, !flag3);
            }
        });
        mengbanSZ.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                mengbanYC.setOpacity(0.87);
                mengbanSZ.setOpacity(0f);
                mengban2D.setOpacity(0.87f);
                flag1=false;
                flag2=true;
                flag3=true;
                arrow.setOpacity(1);
                arrow1.setOpacity(0);
                arrow2.setOpacity(0);
                //背景
                iv_but_back.setOpacity(0);
                iv_but1_back.setOpacity(1);
                iv_but2_back.setOpacity(1);
                myProgramUI.setPage(!flag1, !flag2, !flag3);
            }
        });
        mengbanYC.setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent event) {
                mengbanYC.setOpacity(0);
                mengbanSZ.setOpacity(0.87f);
                mengban2D.setOpacity(0.87f);
                flag3=false;
                flag1=true;
                flag2=true;
                arrow.setOpacity(0);
                arrow1.setOpacity(0);
                arrow2.setOpacity(1);
                //背景
                iv_but_back.setOpacity(1);
                iv_but1_back.setOpacity(1);
                iv_but2_back.setOpacity(0);
                myProgramUI.setPage(!flag1, !flag2, !flag3);
            }
        });
        //装载各种tooltip
        Tooltip.install(mengban2D, tdTip);
        Tooltip.install(mengbanSZ, szTip);
        Tooltip.install(mengbanYC, ycTip);
    }
}
